package com.rpc.center.register.client.netty;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;
import lombok.Getter;
import lombok.Setter;

public class PipleLineInitializer extends ChannelInitializer<SocketChannel> {
    private NettyRegisterServiceImpl registerService;
    @Getter
    private NettyRegistServiceHandler handler;

    @Override
    protected void initChannel(SocketChannel ch)throws Exception{
        ch.pipeline().addLast(new ObjectDecoder(1024*1024,
        ClassResolvers.weakCachingConcurrentResolver(this.getClass().getClassLoader())));
        ch.pipeline().addLast(new ObjectEncoder());
        ch.pipeline().addLast(handler);
    }

    public PipleLineInitializer(NettyRegisterServiceImpl nettyRegisterService){
        this.registerService=nettyRegisterService;
        handler=new NettyRegistServiceHandler(nettyRegisterService);
    }
}
